package com.css.fxfzypg.modules.saresults.controller;

import cn.hutool.core.io.FileUtil;
import com.css.fxfzypg.base.response.RestResponse;
import com.css.fxfzypg.modules.saresults.param.DrillHoleQueryParam;
import com.css.fxfzypg.modules.saresults.service.DrillHoleQueryService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 钻孔信息综合查询
 */
@RestController
@RequestMapping("drillHoleQuery")
@ComponentScan
public class DrillHoleQueryController {

    @Autowired
    private DrillHoleQueryService drillHoleQueryService;

    /**
     * 分页
     */
    @GetMapping("queryData")
    public RestResponse queryData(DrillHoleQueryParam param, HttpServletRequest request,String geom){
        return drillHoleQueryService.queryData(param,request,geom);
    }

    /**
     * 地图检索切换分页
     */
    @GetMapping("queryMapData")
    public RestResponse queryMapData(DrillHoleQueryParam param, HttpServletRequest request){
        return drillHoleQueryService.queryMapData(param,request);
    }

    /**
     * 根据id查
     */
    @GetMapping("getById")
    public RestResponse getById(String id,String type){
        return drillHoleQueryService.getById(id,type);
    }

    /**
     * 导出数据
     */
    @GetMapping("exportData")
    public void exportData(DrillHoleQueryParam param, HttpServletResponse response) {
        drillHoleQueryService.exportData(param,response);
    }

    /**
     * 导出数据
     */
    @GetMapping("exportDetails")
    public void exportDetails(String id,String type, HttpServletResponse response) {
        drillHoleQueryService.exportDetails(id,type,response);
    }

    /**
     * 导入数据
     */
    @PostMapping("uploadDetails")
    public RestResponse uploadDetails(@RequestParam MultipartFile file) {
        if (!FileUtil.getSuffix(file.getOriginalFilename()).equals("xls") && !FileUtil.getSuffix(file.getOriginalFilename()).equals("xlsx")) {
            return RestResponse.fail("文件格式不支持!");
        }
        return drillHoleQueryService.uploadDetails(file);
    }

    @GetMapping("getByGeom")
    public RestResponse getByGeom(DrillHoleQueryParam param,String geom){
        return drillHoleQueryService.getByGeom(param,geom);
    }

    @GetMapping("getListByGeom")
    public RestResponse getListByGeom(String geom, HttpServletRequest request){
        return drillHoleQueryService.getListByGeom(geom,request);
    }



}
